//
//  BigNumber3Cell.m
//  7.13苏宁框架
//
//  Created by mini on 15/7/19.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "BigNumber3Cell.h"
#import "bigDetailModel.h"
#import "GoodSDetailModel.h"
#import "Common.h"
#import "XQModel.h"
#import "BigCollectionViewCell.h"

@implementation BigNumber3Cell


-(instancetype)init
{
    self = [super init];
    if (self) {
        self = [[[NSBundle mainBundle]loadNibNamed:@"BigNumber3Cell" owner:nil options:nil]lastObject];
    }
    return self;
}

- (void)awakeFromNib {
   //创建自定义布局对象
    CustomLayout *layout = [[CustomLayout alloc]init];
    layout.delegate = self;
   //创建CollectionView
    UICollectionView *collectionView  = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:layout];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [self addSubview:collectionView];
    self.collectionView = collectionView;
    self.collectionView.height = 1910;
    self.collectionView.backgroundColor = [UIColor colorWithRed:238.0/255 green:238.0/255 blue:238.0/255 alpha:1];
    //注册单元格
    [self.collectionView registerNib:[UINib nibWithNibName:@"BigCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"bigCell"];
    //添加手势识别器
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushModel:)];
    [self.collectionView addGestureRecognizer:tap];
}

-(NSArray*)total
{
    _total = [NSArray array];
    _total = [bigDetailModel modelArrayWithFilename:@"bigDetail.plist"];
    return _total;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.total.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BigCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bigCell" forIndexPath:indexPath];
    cell.model = _total[indexPath.item];
    return cell;
}

- (CGFloat)waterflowLayout:(CustomLayout *)waterflowLayout heightForWidth:(CGFloat)width atIndexPath:(NSIndexPath *)indexPath
{
    bigDetailModel *model = self.total[indexPath.item];
    CGFloat w = [model.w floatValue];
    CGFloat h = [model.h floatValue];
    return w/h*w;
}

-(void)pushModel:(UITapGestureRecognizer*)tap
{
    CGPoint point = [tap locationInView:self.collectionView];
    for (BigCollectionViewCell *cell in self.collectionView.subviews) {
        if (CGRectContainsPoint(cell.frame, point)) {
            bigDetailModel *model = cell.model;
            XQModel *xqmodel = [[XQModel alloc]init];
            xqmodel.image = model.image;
            xqmodel.name = model.name;
            xqmodel.price = model.price;
            xqmodel.oldprice = model.oldprice;
            xqmodel.know = model.know;
            xqmodel.fuwu = model.fuwu;
            xqmodel.hpl = model.hpl;
            xqmodel.person = model.person;
            xqmodel.pj = model.pj;
            xqmodel.detailpj = model.detailpj;
            xqmodel.smallimage = model.smallimage;
            xqmodel.type = model.type;
            if ([self.delegate respondsToSelector:@selector(bigPush:)]) {
                [self.delegate bigPush:xqmodel];
            }

        }
    }
    
}
@end
